import Vue from 'vue';
import add from "./add";
import './../../styles/tables.scss'
import router from './../../router'



function system(setting) {
  setting.created()
  //new Promise(function (resolve, reject) {
  Vue.prototype.post({ batchId: setting.batchid }, 'services/app/policy/GetPolicyListByTemplate').then(res => {
    var ps = document.getElementById('ps');
    var newdiv = document.createElement("div");
    newdiv.id = 'ceshi'
    ps.appendChild(newdiv)
    var div = document.getElementById('ceshi');
    let data = res.result.excelHtml;
    let policylist = res.result.items;
    policylist.map(function(item) {
      item.isbackshow = false;
      item.change1 = false;
      item.change2 = false;
      item.change3 = false;
      item.change4 = false;
      if(item.childOrgs instanceof Array){
        item.childOrgs.map(function(obj){
          obj.isbackshow = false;
          obj.change1 = false;
          obj.change2 = false;
          obj.change3 = false;
          obj.change4 = false;
        })
      }
    });
    let str = JSON.stringify(policylist);
    
    let copypolicylist  = JSON.parse(str);
    if (res.success) {
      var vm = new Vue({
        el: div,
        template: data,
        data() {
          const datas = policylist
          return {
            visible2: false,
            policylist:datas,
            stream:0,
            copypolicylist:copypolicylist,
            iscanedit: false,
            moresave: false,
            isNull: false,
            batchDialog: false,
            dialogTitle: "",
            organization: [],
            isSingle: false,
            childloding: false,
            batchChild: {},
            id: "7ac8a357-a759-491b-a2f0-897e455269d7",
            rules: {
              targetId: [
                {
                  required: true,
                  message: "请选择对象",
                  trigger: "change"
                }
              ]
            },
            datas: [],
            childorganization:[]
          };
        },
        filters: {
          isPercentage(val) {
            if (val == 0) {
              return "%";
            } else {
              return "元";
            }
          }
        },
        mounted() {
          // new system()
          // console.log(system);
          setting.success(this.datas)
          console.log(this.datas)
          this.stream = this.policylist[0].stream
        },
        methods: {
         
          //上游编辑确定
          subpolicy(ref) {
            console.log(this.additional)
            let brokerageBusinessType = this.additional.brokerageBusinessType;
            let upperBrokerageBusiness = Number(
              this.additional.upperBrokerageBusiness
            );
            let upperRewardBusiness = Number(this.additional.upperRewardBusiness);
            let upperBrokerageTraffic = Number(this.additional.upperBrokerageTraffic);
            let upperRewardTraffic = Number(this.additional.upperRewardTraffic);

            let params = {
              items: [{
                policyId: this.additional.policyId,
                upperBrokerageBusiness: this.additional.upperBrokerageBusiness,
                upperRewardBusiness: this.additional.upperRewardBusiness,
                upperBrokerageTraffic: this.additional.upperBrokerageTraffic,
                upperRewardTraffic: this.additional.upperRewardTraffic
              }]
            }
            //setting.success(vm);
            // system(setting.batchid)

            if (brokerageBusinessType == 0) {
              //0是百分比 1是元
              if (upperBrokerageBusiness + upperRewardBusiness > 100) {
                console.log(
                  upperBrokerageBusiness + upperRewardBusiness,
                  "百分比大于100"
                );
                this.shangye = true;
              } else {
                this.shangye = false;
              }
              if (upperBrokerageTraffic + upperRewardTraffic > 100) {
                this.jiaoqiang = true;
              } else {
                this.jiaoqiang = false;
              }
              if (upperBrokerageBusiness + upperRewardBusiness <= 100 && upperBrokerageTraffic + upperRewardTraffic <= 100) {
                console.log("这是ok的");
                this.post(params, "services/app/policy/UpdateUpperPolicyCustom").then(
                  rs => {
                    if (rs.success) {
                      console.log("success");
                      console.log(rs);
                      this.$refs[ref].doClose();
                      system(setting)
                      ps.removeChild(vm.$el);
                      vm.$destroy()
                    } else {
                      this.$notify.error({
                        title: "错误",
                        message: res.error.message
                      });
                    }
                  }
                );

              }
            } else {
              console.log("走到了这里")
              this.post(params, "services/app/policy/UpdateUpperPolicyCustom").then(
                rs => {
                  if (rs.success) {
                    this.$refs[ref].doClose();
                    system(setting)
                    ps.removeChild(vm.$el);
                    vm.$destroy()
                  } else {
                    this.$notify.error({
                      title: "错误",
                      message: res.error.message
                    });
                  }
                }
              );
              //this.iseditshow = false;
            }
          },
           //下游编辑确定
           downsubpolicy(ref) {
            console.log(this.additional)
            let brokerageBusinessType = this.additional.brokerageBusinessType;
            let upperBrokerageBusiness = Number(
              this.additional.upperBrokerageBusiness
            );
            let upperRewardBusiness = Number(this.additional.upperRewardBusiness);
            let upperBrokerageTraffic = Number(this.additional.upperBrokerageTraffic);
            let upperRewardTraffic = Number(this.additional.upperRewardTraffic);

            let params = {
              items: [{
                policyItemRateId : this.additional.policyId,
                lowerBrokerageBusiness: this.additional.upperBrokerageBusiness,
                lowerRewardBusiness: this.additional.upperRewardBusiness,
                lowerBrokerageTraffic: this.additional.upperBrokerageTraffic,
                lowerRewardTraffic: this.additional.upperRewardTraffic
              }]
            }
            //setting.success(vm);
            // system(setting.batchid)

            if (brokerageBusinessType == 0) {
              //0是百分比 1是元
              if (upperBrokerageBusiness + upperRewardBusiness > 100) {
                console.log(
                  upperBrokerageBusiness + upperRewardBusiness,
                  "百分比大于100"
                );
                this.shangye = true;
              } else {
                this.shangye = false;
              }
              if (upperBrokerageTraffic + upperRewardTraffic > 100) {
                this.jiaoqiang = true;
              } else {
                this.jiaoqiang = false;
              }
              if (upperBrokerageBusiness + upperRewardBusiness <= 100 && upperBrokerageTraffic + upperRewardTraffic <= 100) {
                console.log("这是ok的");
                this.post(params, "services/app/policy/LowerUpdate").then(
                  rs => {
                    if (rs.success) {
                      console.log("success");
                      console.log(rs);
                      this.$refs[ref].doClose();
                      system(setting)
                      ps.removeChild(vm.$el);
                      vm.$destroy()
                    } else {
                      this.$notify.error({
                        title: "错误",
                        message: res.error.message
                      });
                    }
                  }
                );

              }
            } else {
              console.log("走到了这里")
              this.post(params, "services/app/policy/LowerUpdate").then(
                rs => {
                  if (rs.success) {
                    this.$refs[ref].doClose();
                    system(setting)
                    ps.removeChild(vm.$el);
                    vm.$destroy()
                  } else {
                    this.$notify.error({
                      title: "错误",
                      message: res.error.message
                    });
                  }
                }
              );
              //this.iseditshow = false;
            }
          },
          //确定删除
          deletepolicy(ref, policyBatchType, policyId, policyItemRatesID) {
            let params = {
              policyBatchType: policyBatchType,
              policyId: policyId
            };
            if (policyItemRatesID) {
              params.policyItemRatesID = policyItemRatesID;
            }
            this.post(params, "services/app/policy/DeletePolicy").then(res => {
              console.log(res);
              if (res.success) {
                this.$notify({
                  title: "删除成功",
                  message: "您已成功删除一条政策",
                  type: "success",
                  customClass: "el-notification-success"
                });
                this.$refs[ref].doClose();
                system(setting)
                    ps.removeChild(vm.$el);
                    vm.$destroy()
              } else {
                this.$notify.error({
                  title: "错误",
                  message: res.error.message
                });
              }
            });
          },
          focusselect(val) {
            val.currentTarget.select();
          },
          subfalse(index) {
            console.log(this.copypolicylist)
            let str = JSON.stringify(this.copypolicylist[index]);
            Vue.set(this.policylist, index, JSON.parse(str));
            this.nowmoresave();
          },
          //判断moresave
          nowmoresave() {
            let aa = false;
            this.policylist.map(item => {
              if (item.isbackshow) {
                aa = true;
              }
              if (item.childOrgs !== null && item.childOrgs.length != 0) {
                item.childOrgs.map(val => {
                  if (val.isbackshow) {
                    aa = true;
                  }
                });
              }
            });
            this.moresave = aa;
          },
          moresaves() {
            if (this.moresave) {
              console.log(this.policylist);
              let arr = [];
              let aa = false;
              this.policylist.map(item => {
                if (item.isbackshow) {
                  let obj = {
                    policyItemRateId: item.id,
                    lowerBrokerageBusiness: item.brokerageBusiness,
                    lowerRewardBusiness: item.rewardBusiness,
                    lowerBrokerageTraffic: item.brokerageTraffic,
                    lowerRewardTraffic: item.rewardTraffic,
                    extendID:item.policyItemRateId
                  };
                  let upobj={
                    policyId: item.policyId,
                            upperBrokerageBusiness: item.brokerageBusiness,
                            upperRewardBusiness: item.rewardBusiness,
                            upperBrokerageTraffic: item.brokerageTraffic,
                            upperRewardTraffic: item.rewardTraffic
                  }
                  item.extendID = item.policyItemRateId;
                  if(this.policylist[0].stream == 1){
                    arr.push(upobj);
                  }else{
                    arr.push(obj);
                  }
                  
                }
                if (item.isfront || item.issecon) {
                  aa = true;
                }
                if(item.childOrgs  instanceof Array ){
                  item.childOrgs.map(val => {
                    if (val.isbackshow) {
                      val.extendID = val.policyItemRateId;
                      let obj = {
                        policyItemRateId: val.id,
                        lowerBrokerageBusiness: val.brokerageBusiness,
                        lowerRewardBusiness: val.rewardBusiness,
                        lowerBrokerageTraffic: val.brokerageTraffic,
                        lowerRewardTraffic: val.rewardTraffic
                      };
                     
                      
                        arr.push(obj);
                     // arr.push(val);
                    }
                    if (val.isfront || val.issecon) {
                      aa = true;
                    }
                  });
                }
                
              });
              console.log(arr)
              if (aa == true) {
                this.$message({
                  message: "数据不对",
                  type: "warning"
                });
              } else {
                var txt = "确定批量保存吗？";
                this.$confirm(txt, "保存提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  closeOnClickModal: false
                  // type: 'warning'
                }).then(() => {
                  let params = {}
                  let url =''
                  if(this.policylist[0].stream == 1){
                    url = "services/app/policy/UpdateUpperPolicyCustom"
                    params = {
                      items: arr
                    };
                  }else{
                    url ="services/app/policy/LowerUpdate"
                    params = {
                      batchID:setting.batchid,
                      items: arr
                    };
                  }
                 
                  this.post(params, url).then(rs => {
                    if (rs.success) {
                      console.log("success");
                      console.log(rs);
                    //  this.getPolicyList();
                      this.$notify({
                        title: "修改成功",
                        message: "您已修改成功",
                        type: "success",
                        customClass: "el-notification-success"
                      });
                      this.moresave = false;
                      system(setting)
                      ps.removeChild(vm.$el);
                      vm.$destroy()
                    } else {
                      this.$notify.error({
                        title: "错误",
                        message: rs.error.message
                      });
                    }
                  });
                });
              }
            }
          },
          //修改单条政策数据
          subpolicy(item, index) {
            let obj = {
              policyItemRateId: item.policyId,
              lowerBrokerageBusiness: item.brokerageBusiness,
              lowerRewardBusiness: item.rewardBusiness,
              lowerBrokerageTraffic: item.brokerageTraffic,
              lowerRewardTraffic: item.rewardTraffic,
            };
            let upobj={
              policyId: item.policyId,
                      upperBrokerageBusiness: item.brokerageBusiness,
                      upperRewardBusiness: item.rewardBusiness,
                      upperBrokerageTraffic: item.brokerageTraffic,
                      upperRewardTraffic: item.rewardTraffic
            }
            if (item.isfront || item.issecon) {
              this.$message({
                message: "数据不对",
                type: "warning"
              });
            } else {
              this.loading2 = true;
              let arr = [];
              let url =''
              if(item.stream == 1){
                arr.push(upobj);
                url = "services/app/policy/UpdateUpperPolicyCustom"
              }else{
                arr.push(obj);
                url ="services/app/policy/LowerUpdate"
              }
              
              let params = {
                // batchID:item.policyId,
                items: arr
              };
              this.post(params, url).then(rs => {
                if (rs.success) {
                  console.log("success");
                  console.log(rs);
                  //this.getPolicyList()
                  this.$notify({
                    title: "修改成功",
                    message: "您已修改成功",
                    type: "success",
                    customClass: "el-notification-success"
                  });
                  Vue.set(this.policylist[index], "isbackshow", false);
                  Vue.set(this.policylist[index], "change1", false);
                  Vue.set(this.policylist[index], "change2", false);
                  Vue.set(this.policylist[index], "change3", false);
                  Vue.set(this.policylist[index], "change4", false);
                  let str = JSON.stringify(this.policylist[index]);
                  Vue.set(this.copypolicylist, index, JSON.parse(str));
                  this.nowmoresave();
                  system(setting)
                  ps.removeChild(vm.$el);
                  vm.$destroy()
                  this.loading2 = false;
                } else {
                  this.loading2 = false;
                  this.$notify.error({
                    title: "错误",
                    message: rs.error.message
                  });
                }
              });
            }
          },
          //信息表
          getPolicyList() {
            let params = {
              // 'id':'fdafdafd-e6eb-4068-ac7e-c09853094735'
              id: this.id
            };
            this.post(params, "services/app/policy/GetAllPolicyList").then(rs => {
              if (rs.success) {
                console.log("biaoshuju");
                console.log(rs.result.items);
                if (rs.result.items.length == 0) {
                  this.isNull = true;
                }
                this.policylist = rs.result.items;
                let re = /^[0-9]+.?[0-9]*/;
                this.policylist.forEach(item => {
                  if (item) {
                    item.hovershow = false;
                    item.Lowerpassiseditshow = false;
                    item.isbackshow = false;
                    item.isfront = false;
                    item.issecon = false;
                    item.change1 = false;
                    item.change2 = false;
                    item.change3 = false;
                    item.change4 = false;
                    item.detailshow = false;
                    item.delete_show = false;
                    if (item.childOrgs.length != 0) {
                      item.childOrgs.map(val => {
                        val.hovershow = false;
                        item.isbackshow = false;
                        item.isfront = false;
                        item.issecon = false;
                        item.change1 = false;
                        item.change2 = false;
                        item.change3 = false;
                        item.change4 = false;
                      });
                    }
                  }
                });
                let str = JSON.stringify(this.policylist);
                this.copypolicylist = JSON.parse(str);
              }
            });
          },
          //扩展input
          getchange_extendnum(val, indexout, index, name, types) {
            let aa = this.api.clearNoNum_target(val, 100, types);
            console.log(aa);
            Vue.set(this.policylist[indexout].childOrgs[index], name, aa);
            Vue.set(this.policylist[indexout].childOrgs[index], "isbackshow", true);
            this.moresave = true;
            //lowerRewardTraffic
            let a1 = parseFloat(
              this.policylist[indexout].childOrgs[index].lowerBrokerageTraffic
            );
            let a2 = parseFloat(
              this.policylist[indexout].childOrgs[index].lowerRewardTraffic
            );
            let a3 = parseFloat(
              this.policylist[indexout].childOrgs[index].lowerBrokerageBusiness
            );
            let a4 = parseFloat(
              this.policylist[indexout].childOrgs[index].lowerRewardBusiness
            );
            if (name == "brokerageTraffic") {
              Vue.set(this.policylist[indexout].childOrgs[index], "change1", true);
            }
            if (name == "rewardTraffic") {
              Vue.set(this.policylist[indexout].childOrgs[index], "change2", true);
            }
            if (name == "brokerageBusiness") {
              Vue.set(this.policylist[indexout].childOrgs[index], "change3", true);
            }
            if (name == "rewardBusiness") {
              Vue.set(this.policylist[indexout].childOrgs[index], "change4", true);
            }
            if (types == 0) {
              if (a1 + a2 > 100) {
                Vue.set(this.policylist[indexout].childOrgs[index], "isfront", true);
              } else {
                Vue.set(this.policylist[indexout].childOrgs[index], "isfront", false);
              }
              if (a3 + a4 > 100) {
                Vue.set(this.policylist[indexout].childOrgs[index], "issecon", true);
              } else {
                Vue.set(this.policylist[indexout].childOrgs[index], "issecon", false);
              }
            }
          },
          //下通input
          getchange_num(val, index, name, types) {
            let aa = this.api.clearNoNum_target(val, 100, types);
            Vue.set(this.policylist[index], name, aa);
            Vue.set(this.policylist[index], "isbackshow", true);
            console.log(this.policylist[index])
            this.moresave = true;
            let a1 = parseFloat(this.policylist[index].brokerageTraffic);
            let a2 = parseFloat(this.policylist[index].rewardTraffic);
            let a3 = parseFloat(this.policylist[index].brokerageBusiness);
            let a4 = parseFloat(this.policylist[index].rewardBusiness);
            if (name == "brokerageTraffic") {
              Vue.set(this.policylist[index], "change1", true);
            }
            if (name == "rewardTraffic") {
              Vue.set(this.policylist[index], "change2", true);
            }
            if (name == "brokerageBusiness") {
              Vue.set(this.policylist[index], "change3", true);
            }
            if (name == "rewardBusiness") {
              Vue.set(this.policylist[index], "change4", true);
            }
            if (types == 0) {
              if (a1 + a2 > 100) {
                console.log("会走到这里的")
                Vue.set(this.policylist[index], "isfront", true);
              } else {
                Vue.set(this.policylist[index], "isfront", false);
              }
              if (a3 + a4 > 100) {
                Vue.set(this.policylist[index], "issecon", true);
              } else {
                Vue.set(this.policylist[index], "issecon", false);
              }
            }
          },
          //扩展取消
          subfalseextend(indexout, index) {
            let str = JSON.stringify(this.copypolicylist[indexout].childOrgs[index]);
            Vue.set(this.policylist[indexout].childOrgs, index, JSON.parse(str));
            this.nowmoresave();
          },
          //修改扩展信息
          subpolicychildOrgs(item, indexout, index) {
            let obj = {
              policyItemRateId: item.policyItemRateId,
              lowerBrokerageBusiness: item.lowerBrokerageBusiness,
              lowerRewardBusiness: item.lowerRewardBusiness,
              lowerBrokerageTraffic: item.lowerBrokerageTraffic,
              lowerRewardTraffic: item.lowerRewardTraffic,
              lowerBrokerageVehicleTax: item.lowerBrokerageVehicleTax,
              lowerRewardVehicleTax: item.lowerRewardVehicleTax
            };
      
            if (item.isfront || item.issecon) {
              this.$message({
                message: "数据不对",
                type: "warning"
              });
            } else {
              this.loading2 = true;
              let arr = [];
              arr.push(obj);
              let params = {
                batchID: this.id,
                items: arr
              };
              this.post(params, "services/app/policy/LowerUpdate").then(rs => {
                if (rs.success) {
                  console.log("success");
                  console.log(rs);
                  //this.getPolicyList()
                  this.$notify({
                    title: "修改成功",
                    message: "您已修改成功",
                    type: "success",
                    customClass: "el-notification-success"
                  });
                  Vue.set(
                    this.policylist[indexout].childOrgs[index],
                    "isbackshow",
                    false
                  );
                  Vue.set(
                    this.policylist[indexout].childOrgs[index],
                    "change1",
                    false
                  );
                  Vue.set(
                    this.policylist[indexout].childOrgs[index],
                    "change2",
                    false
                  );
                  Vue.set(
                    this.policylist[indexout].childOrgs[index],
                    "change3",
                    false
                  );
                  Vue.set(
                    this.policylist[indexout].childOrgs[index],
                    "change4",
                    false
                  );
                  let str = JSON.stringify(
                    this.policylist[indexout].childOrgs[index]
                  );
                  Vue.set(
                    this.copypolicylist[indexout].childOrgs,
                    index,
                    JSON.parse(str)
                  );
                  this.nowmoresave();
                 
                  this.loading2 = false;
                } else {
                  this.loading2 = false;
                  this.$notify.error({
                    title: "错误",
                    message: res.error.message
                  });
                }
              });
            }
          },
          //详情
          toDetail(val, see) {
            console.log(val)
            console.log(setting.source);
            
            //dawn_policydowninfo
            let filterType;
            if (see == "02") {
              filterType = 1;
            } else {
              filterType = 0;
            }
            
            if(vm.stream == 2){ //stream 1是上游 2 是下游
              if (setting.source == "policylower3_list") {
                router.push({
                  name: "down_policydowninfo",
                  query: {
                    batchId: setting.batchid,
                    policyId: val.policyId,
                    status: setting.status,
                    stream: 2,
                 //   Jurisdiction: this.Jurisdiction,
                    filterType: filterType
                  }
                });
              } else {
                router.push({
                  name: "adddown_policydowninfo",
                  query: {
                    batchId: setting.batchid,
                    policyId: val.policyId,
                    status: setting.status,
                    stream: 2,
                   // Jurisdiction: this.Jurisdiction,
                    filterType: filterType
                  }
                });
              }
            }else{
               //区分从创建过来还是列表归来 左边高亮
               console.log(setting.source)
              if (setting.source == "policyupper3c") {
                router.push({
                  name: "addup_policyupedit",
                  query: {
                    batchId:  setting.batchid,
                    policyId:val.policyId,
                    status: setting.status,
                    stream: 1
                  }
                });
              } else {
                console.log(val.id,val.policyid)
                router.push({
                  name: "up_policyupedit",
                  query: {
                    batchId:  setting.batchid,
                    policyId:val.policyId,
                    status: setting.status,
                    stream: 1
                  }
                });
              }
            }
          },
          tocopy(ids) {
            if (setting.source == "policylower3_list") {
              router.push({
                name: "down_policydowninfo",
                query: {
                  batchId: this.id,
                  policyId: val.id,
                  status: val.state,
                  stream: 2,
                  Jurisdiction: this.Jurisdiction,
                  iscopy: true
                }
              });
            } else {
              router.push({
                name: "adddown_policydowninfo",
                query: {
                  batchId: this.id,
                  policyId: ids,
                  status: val.state,
                  stream: 2,
                  Jurisdiction: this.Jurisdiction,
                  iscopy: true
                }
              });
            }
          },
          deletefalse(val) {
            this.$refs[val][0].doClose();
          },
          cancelpop(val){
             this.$refs[val][0].doClose();
          },
          //删除政策
          deletepolicy(val, e, refss) {
            console.log(val);
            let params = {
              //policyBatchType: 1,
              policyId: val
              //policyItemRatesID: val.policyItemRateId,
            };
            this.post(params, "services/app/policy/DeletePolicy").then(res => {
              console.log(res);
              if (res.success) {
                this.$notify({
                  title: "删除成功",
                  message: "您已成功删除一条政策",
                  type: "success",
                  customClass: "el-notification-success"
                });
                this.$refs[refss][0].doClose();
                this.policylist.splice(e, 1);
                if (this.policylist.length == 0) {
                  this.isNull = true;
                }
              } else {
                this.$notify.error({
                  title: "错误",
                  message: res.error.message
                });
              }
            });
          },
          //批量添加子机构
          batchNew() {
            // this.dialogTitle = "批量添加子机构政策"
            this.isSingle = false;
            //this.batchDialog = true;
            this.batchChild = {};
            this.gethomes(this.id);
          },
          //获取组织
          gethomes(val) {
            //organization
            let params = {
              id: val
            };
            this.post(params, "services/app/policy/ChildOrganizations").then(res => {
              console.log(res);
              if (res.success) {
                console.log("zuzhi");
                console.log(res);
                this.organization = res.result.all;
              } else {
                this.$notify.error({
                  title: "错误",
                  message: res.error.message
                });
              }
            });
          },
          //单个增加子机构
          singleAdd(policyId) {
            this.childpolicyId = policyId;
         //  this.dialogTitle = "添加子机构政策";
            this.isSingle = true;
            //this.batchDialog = true;
            this.getChildhomes(policyId);
          },
          //批量or单个新增子机构保存
          saveBatchchild(formName,type) {
            console.log(formName)
            console.log(this.$refs[formName])
            const me = this;
            let dom;
            if(type == 2){
              dom = this.$refs[formName]
            }else{
              dom = this.$refs[formName][0]
            }
            dom.validate(valid => {
              if (valid) {
                me.childloding = true;
                let params = {
                  policyBatchId: setting.batchid,
                  extendType: 1,
                  targetId: this.batchChild.targetId+''
                };
                if (me.isSingle) {
                  params.policyId = this.childpolicyId;
                }
                this.post(params, "services/app/policy/CreateLowerPolicyExtend").then(
                  rs => {
                    console.log(rs);
                    if (rs.success) {
                      this.$notify({
                        title: "添加成功",
                        message: "批量添加子机构政策成功",
                        type: "success",
                        customClass: "el-notification-success"
                      });
                      me.batchDialog = false;
                      me.batchChild.targetId = "";
                      // me.getPolicyList();
                      me.childloding = false;
                      system(setting)
                      ps.removeChild(vm.$el);
                      vm.$destroy()
                    } else {
                      this.$notify.error({
                        title: "错误",
                        message: res.error.message
                      });
                      me.childloding = false;
                    }
                  }
                );
              } else {
                console.log("验证不通过");
              }
            });
          },
          //删除子机构
          deletChild(policyid, ratesid) {
            const me = this;
            let params = {
              policyId: policyid,
              policyItemRatesID: ratesid
            };
            this.$confirm("您确定要删除子机构政策吗?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              this.post(params, "services/app/policy/DeleteExtendPolicy").then(
                res => {
                  if (res.success) {
                    this.$notify({
                      title: "删除成功",
                      message: "删除子机构政策成功",
                      type: "success",
                      customClass: "el-notification-success"
                    });
                    me.getPolicyList();
                  } else {
                    this.$notify.error({
                      title: "错误",
                      message: res.error.message
                    });
                  }
                }
              );
            });
          },
          //获取组织
          getChildhomes(val) {
            //organization
            let params = {
              id: val
            };
            this.post(params, "services/app/policy/ChildOrganizations").then(res => {
              if (res.success) {
                this.childorganization = res.result.child;
              } else {
                this.$notify.error({
                  title: "错误",
                  message: res.error.message
                });
              }
            });
          },
      
          //数字小数点
          clearNoNum(obj, max) {
            obj = obj.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
            obj = obj.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj = obj
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            obj = obj.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
            if (obj.indexOf(".") < 0 && obj != "") {
              //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
              obj = parseFloat(obj);
            }
            if (max && obj > max) {
              obj = max;
            }
            if (obj == "") {
              obj = 0;
            }
            console.log(obj);
            return obj;
          }
        }
      })

    }


  })


}
export default system